﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Book_Shop.DAL.DAO;
using Book_Shop.DAL.DAO.CustomException;
using Book_Shop.DAL.Gateway;

namespace Book_Shop.BLL
{
    public class SalesManager
    {
        private InventoryGateway inventoryGateway = new InventoryGateway();
        private OrderGateway  orderGateway = new OrderGateway();

        public bool IsInventoryContainsTheRightAmountOfBookAtThisShop(Book book,Shop thisShop)
        {
            int amountOfBooks = inventoryGateway.GetAmountOfBooksAtThisShop(book,thisShop);
            if (book.Qty<=amountOfBooks)
            {
                return true;
            }
            else
            {
                throw new NotSufficientBookException();
            }
        }
        public string CheckOut(OrderSheet orderSheet)
        {
            try
            {
                if (orderGateway.CheckOutBooks(orderSheet))
                {
                    return "CheckOut Succeed!";
                }
            }
            catch (Exception exception)
            {
                
                throw exception;
            }
            return "";
        }

    }
}